import Vue from 'vue'
import {_baseUrl, parseParam} from "./serveConfig";

const userInfoUrl = `${_baseUrl}/api/user/info`
export const GetUserInfoApi = (user_id) => {
  let url = `${userInfoUrl}/${user_id}`
  return Vue.prototype.$post(`${url}`)
}

const userListUrl = `${_baseUrl}api/user/list`
export const GetUserListApi = (cur_page, page_size) => {
  let user_payload = {
    "Page": cur_page === undefined ? 1 : cur_page,
    "Limit": page_size === undefined ? 5 : page_size,
    "Sort": "",
    "Where": ""
  }
  let p = parseParam(user_payload)
  let rand = (Math.random() * 100000)
  let url = `${userListUrl}?${p}&rand=${rand}`
  return Vue.prototype.$fetch(`${url}`)
}

const userAddUrl = `${_baseUrl}api/user/add`
export const AddUserApi = (user) => {
  return Vue.prototype.$post(`${userAddUrl}`, user)
}


const userEditUrl = `${_baseUrl}api/user/edit`
export const EditUserApi = (user) => {
  return Vue.prototype.$post(`${userEditUrl}`, user)
}


const userDeleteUrl = `${_baseUrl}api/user/delete`
export const DeleteUserApi = (id) => {
  return Vue.prototype.$post(`${userDeleteUrl}/${id}`)
}



